import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class WtbController extends GetxController {
  final data = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"].obs;

  /// UI 组件
  final RefreshController refreshController = RefreshController(
    initialRefresh: false,
  );

  /// 事件

  void onRefresh() async {
    await Future.delayed(const Duration(milliseconds: 1000));
    data.removeRange(10, data.length);
    refreshController.refreshCompleted();
  }

  void onLoading() async {
    await Future.delayed(const Duration(milliseconds: 1000));
    final count = data.length;
    for (int i = 0; i < 10; i++) {
      data.add("Item ${count + i + 1}");
    }
    refreshController.loadComplete();
  }

  /// 生命周期

  ///dispose 释放内存
  @override
  void dispose() {
    super.dispose();
    // dispose 释放对象
    refreshController.dispose();
  }
}
